package cn.edu.zut.cs.service;

import cn.edu.zut.cs.Model.Student;
import cn.edu.zut.cs.Dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StudentService {
    StudentDao studentDao;

    @Autowired
    public void setStudentDao(StudentDao studentDao) {
        this.studentDao = studentDao;
        System.out.println(studentDao.toString());
    }

    @Transactional
    public void insert(Student student) {
        studentDao.addStudent(student);
    }

    @Transactional
    public List<Student> queryAll() {
        return studentDao.getAllStudents();
    }
    @Transactional
    public Student getStudent(int no) {
        return studentDao.getStudentByNo(no);
    }
    @Transactional
    public void update(Student student) {
        studentDao.updateStudent(student);
    }
    @Transactional
    public void delete(Student student) {
        studentDao.deleteStudent(student);
    }
}
